#lang rosetta-racket


(provide shelter)


(define (cut-pipe x y z p r l)
  (subtract
   (move (xyz x y z) p)
   (move (*c uy (- l)) (sphere r))))

(define (shelter w l h nx ny nz r)
  (let* ((p-r (/ w nx 2))
         (p-l (/ l ny))
         (p (rotate (/ pi 2) ux
                    (pipe (- p-r 0.1) p-r p-l))))
    (for/list ((zi (: nz)))
      (for/list ((yi (: ny)))
        (for/list ((xi (: nx)))
          (let ((x (- (+ (* p-r 2 xi) p-r) (/ w 2)))
                (y (* p-l yi))
                (z (+ (* p-r 2 zi) p-r)))
            (cut-pipe x y z p r l)))))))